package org.example.erp.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.example.erp.domain.DeviceType;
import org.example.erp.domain.UserLoginLog;
import org.example.erp.service.impl.DeviceTypeServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api")
public class ReversoContextsController {
    @Autowired
    private DeviceTypeServiceImpl deviceTypeService;

    @DeleteMapping("/reversoContexts/delete")
    public DataResult deleteLoginLog(@RequestBody List<String> deviceTypeNo) {
        if(deviceTypeNo.isEmpty()){
            deviceTypeService.remove(null);
        }else{
            deviceTypeService.removeByIds(deviceTypeNo);
        }
        return DataResult.success();
    }

    @GetMapping("/reversoContexts/find")
    public DataResult findReversoContexts(@RequestParam(value = "currentPage",defaultValue = "1") Integer currentPage,
                                   @RequestParam(value = "pageSize",defaultValue = "1") Integer pageSize,
                                   @RequestParam(required = false) String deviceTypeName,@RequestParam(required = false) String enable
                                  ){
        LambdaQueryWrapper<DeviceType> deviceType = new LambdaQueryWrapper<>();
        IPage<DeviceType> page = new Page<>(currentPage,pageSize);
        if (deviceTypeName != null && !deviceTypeName.isEmpty()) {
            deviceType.like(DeviceType::getDeviceTypeName, deviceTypeName);
        }
        if (enable != null && !enable.isEmpty()) {
            deviceType.like(DeviceType::getEnable, enable);
        }

        IPage<DeviceType> pageResult = deviceTypeService.page(page, deviceType);
        return DataResult.success(pageResult);
    }
    @PostMapping("/reversoContexts/insert")
    public DataResult insertReversoContexts(@RequestBody DeviceType deviceType){
        deviceTypeService.save(deviceType);
        return DataResult.success();
    }
    @PutMapping("/reversoContexts/update")
    public DataResult updateReversoContexts(@RequestBody DeviceType deviceType){
        deviceTypeService.updateById(deviceType);
        return DataResult.success();   
    }



}
